package com.mbc.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mbc.mapper.ConcernMapper;
import com.mbc.pojo.MbcConcern;
import com.mbc.service.ConcernService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 关注表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-04-08
 */
@Service
public class ConcernServiceImpl implements ConcernService {

    @Autowired
    private ConcernMapper concernMapper;

    /**
     * 获取所有用户 ID
     *
     * @param userId 用户 ID
     * @param page   页
     * @param size   大小
     * @return {@link List}<{@link MbcConcern}>
     */
    @Override
    public PageInfo<MbcConcern> getAllByuserId(String userId, Integer page , Integer size) {
        PageHelper.startPage(page,size);
        List<MbcConcern> list = concernMapper.getAllByuserId(userId);
        return new PageInfo<>(list);
    }

    /**
     * 删除关注 ID
     *
     * @param concernId 关注点 ID
     * @return boolean
     */
    @Override
    public boolean deleteConcernId(Integer concernId) {
        return concernMapper.deleteConcernId(concernId) > 0;
    }

    /**
     * 插入关注点
     *
     * @param userId    用户 ID
     * @param concernId 关注点 ID
     * @return boolean
     */
    @Override
    public boolean insertConcern(Integer userId, Integer concernId) {
        LocalDateTime now = LocalDateTime.now();
        return concernMapper.insertConcern(userId,concernId,now) > 0;
    }
}
